package com.haoma.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoma.entity.Visitor;
import com.haoma.mapper.VisitorMapper;
import com.haoma.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Description:
 */
@Service
public class VisitorServiceImpl extends ServiceImpl<VisitorMapper, Visitor> implements VisitorService {

    @Autowired
    private VisitorMapper visitorMapper;

    public List<Visitor> getVisitorList() {
        IPage page = new Page(1,7);
        // 获取到当前日期
        String format = DateUtil.format(new Date(), "yyyy-MM-dd");
        // 小于当前日期的7条
        LambdaQueryWrapper<Visitor> visitorLambdaQueryWrapper = new LambdaQueryWrapper<>();
        visitorLambdaQueryWrapper.le(Visitor::getTime, format);
        visitorLambdaQueryWrapper.orderByDesc(Visitor::getTime);
        visitorMapper.selectPage(page, visitorLambdaQueryWrapper);
        return page.getRecords();
    }
}
